package com.xx.ems.service.impl;

import java.util.Map;

import org.springframework.stereotype.Service;

import com.xx.ems.model.Users;
import com.xx.ems.service.UserCRUDService;
import com.xx.ems.system.BaseService;

@Service(value="userCRUDService")
public class UserCRUDServiceImpl extends BaseService implements UserCRUDService {
	@Override
	public boolean addUser(Users users) {
		try{
			getTransaction().begin();
			getUsersCRUDDao().addUser(users);
			getTransaction().commit();
			return true;
		}catch (Exception e) {
			e.printStackTrace();
			getTransaction().rollback();
			return false;
		}
	}

	@Override
	public boolean updateUser(Users users) {
		try{
			getTransaction().begin();
			getUsersCRUDDao().updateUser(users);
			getTransaction().commit();
			return true;
		}catch (Exception e) {
			e.printStackTrace();
			getTransaction().rollback();
			return false;
		}
	}

	@Override
	public boolean deleteUser(int id) {
		try{
			getTransaction().begin();
			getUsersCRUDDao().deleteUser(id);
			getTransaction().commit();
			return true;
		}catch (Exception e) {
			getTransaction().rollback();
			return false;
		}
	}
	
	@Override
	public String isExistUser(String account) {
		String username = getUsersCRUDDao().isExistUser(account);
		return username;
	}

	@Override
	public Users getSpecificUser(String account) {
		Users user = getUsersCRUDDao().getSpecificUser(account);
		return user;
	}

	@Override
	public Map<String, Object> getUsersList(int pageNow, int maxCount) {
		return getUsersList(pageNow, maxCount);
	}
}